package com.frxuexi.repair

import androidx.lifecycle.MutableLiveData
import com.frxuexi.lib_base.db.RepairDao
import com.frxuexi.lib_base.entity.RepairBean
import com.frxuexi.lib_base.entity.RepairBeanItem
import com.frxuexi.lib_base.mvvm.BaseViewModel
import com.frxuexi.lib_base.net.ApiService
import com.frxuexi.lib_base.net.VideoApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class RepairViewModel @Inject constructor(val apiService: ApiService, val repairDao: RepairDao):BaseViewModel() {
    val repairsData = MutableLiveData<RepairBean>()

    val repairByNumData = MutableLiveData<RepairBeanItem>()

    val repairByUnameData = MutableLiveData<RepairBean>()

    val repairByIdData = MutableLiveData<RepairBeanItem>()
    val updaterepairData = MutableLiveData<RepairBeanItem>()
    val deleteRepairData = MutableLiveData<Boolean>()
    val addRepairData = MutableLiveData<RepairBeanItem>()

    val addRepairRoomData = MutableLiveData<Long>()

    val repairsRoomData = MutableLiveData<List<RepairBeanItem>>()

    val RepairByIdRoomData = MutableLiveData<RepairBeanItem>()

    val deleteRepairRoomData = MutableLiveData<Int>()
    val updateRepairRoomData = MutableLiveData<Int>()
    fun getRepairs(){
        httpRequest({apiService.getRepairs()},repairsData::postValue)
    }

    fun getRepairByNum(num:String){
        httpRequest({apiService.getRepairByNum(num)},repairByNumData::postValue)
    }

    fun getRepairByUname(name:String){
        httpRequest({apiService.getRepairByUname(name)},repairByUnameData::postValue)
    }

    fun getRepaidById(id:Int){
        httpRequest({apiService.getRepairById(id)},repairByIdData::postValue)
    }

    fun updateRepair(id: Int,item:RepairBeanItem){
        httpRequest({apiService.updateRepair(id,toBody(item))},updaterepairData::postValue)
    }

    fun deleteRepair(id: Int){
        httpRequest({apiService.deleteRepair(id)},deleteRepairData::postValue)
    }

    fun addRepair(item:RepairBeanItem){
        httpRequest({apiService.addRepair(toBody(item))},addRepairData::postValue)
    }

    fun addRepairRoom(item: RepairBeanItem){
        roomRequest({repairDao.insertRepair(item)},addRepairRoomData::postValue)
    }

    fun getRepairsRoom(){
        roomRequest({repairDao.getRepairs()},repairsRoomData::postValue)
    }

    fun getRepairByIdRoom(id: Int){
        roomRequest({repairDao.getRepairById(id)},RepairByIdRoomData::postValue)
    }

    fun deleteRepairRoom(item: RepairBeanItem){
        roomRequest({repairDao.deleteRepair(item)},deleteRepairRoomData::postValue)
    }

    fun updateRepairRoom(item: RepairBeanItem){
        roomRequest({repairDao.updateRepair(item)},updateRepairRoomData::postValue)
    }
}